import QtQuick 2.6
import Qt.labs.controls 1.0

TextField {
    id: tf
    signal clikced()

    rightPadding: tb.availableWidth * 1.3
    inputMask: "9999"

    function start() {tm.start()}
    function reset() {tm.stop(); tb.value = 120}
    ToolButton {
        id: tb
        property int value: 120
        text: tm.running ? ("重新发送" + value + "秒"): "获取验证码"
        width: iWIDTH * 7
        anchors.right: parent.right
        anchors.rightMargin: 1 * __factor__
        anchors.verticalCenter: parent.verticalCenter
        onClicked: { tf.clikced() }
        enabled: !tm.running
    }

    Timer {
        id: tm
        running: false
        repeat: true
        triggeredOnStart: true
        onTriggered: {
            if (tb.value > 0) {
                tb.value -= 1
            }
            else {
               tf.reset()
            }
        }

    }

}

